//
//  HotViewcontroller.m
//  YSBEmployee
//
//  Created by developer on 2021/11/30.
//  Copyright © 2021 ysb. All rights reserved.
//

#import "AppDelegate.h"
#import "YSBOrderDefaultViewController.h"

#import "SnatchingOrdersView.h"
#import "YSBMessageHeaderView.h"


@implementation AppDelegate


- (void)faceStart {
    [self.locationManager startUpdatingLocation];
    
}


- (void)faceStop {
    [self.locationManager stopUpdatingLocation];
    
}


@end




@implementation SnatchingOrdersView


- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title andOrderModel:(YSBOrderModel *)model leftButtonTitle:(NSString *)leftButtonTitle rightButtonTitle:(NSString *)rightButtonTitle andLeftAction:(void(^)(void))clickCancelBtnBlock andRightAction:(void(^)(void))clickConfirmBtnBlock {
    
    if (self = [super init]) {
        self.title = title;
        if ([YSBCommonTool isBlankString:model.grab_orders_tip]) {
            model.grab_orders_tip = @"你答应遵守订单规则完成订单。取消订单应该在9小时之前取消，否则将会扣除相应的信用分，确定去抢单吗？";
        }
        self.model = model;
        self.leftButtonTitle = leftButtonTitle;
        self.rightButtonTitle = rightButtonTitle;
        self.clickCancelBtnBlock = clickCancelBtnBlock;
        self.clickConfirmBtnBlock = clickConfirmBtnBlock;
        
        [self setupUIWithFrame:frame];
    }
    return self;
    
}


@end


@implementation YSBOrderDefaultViewController


- (void)doLeftBtnAction {//不同意结算
    
    [self.confirmAlertView hide];
    
    [self performSelector:@selector(disagreeSettlementAction) withObject:nil afterDelay:0];
    
}

//不同意结算执行方法
- (void)disagreeSettlementAction {
    
    if (self.detailModel.ID.integerValue == 0) {
        return;
    }

    if (self.detailModel.appeal_able == 0) {//是否可以申诉 0-可以提交 1-第一次提交 2-第二次提交 ',

        YSBChildOrderDetailComplaintViewController *vc = [[YSBChildOrderDetailComplaintViewController alloc] init];
        vc.task_id = self.detailModel.ID;
        vc.order_id = self.detailModel.oid;
        vc.model = self.detailModel;
        vc.index = self.index;
        [self.naviController pushViewController:vc animated:YES];

    }else{

        //弹窗提示
        NSString *message = @"因该订单补工资申请被拒绝过，请先联系客服介入，再按照客服沟通结果进行操作~ \n400-150-1200";
        UIAlertController *actionAlert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:message preferredStyle:1];
        ///设置左对齐
        UILabel *label1 = [actionAlert.view valueForKeyPath:@"_titleLabel"];
        UILabel *label2 = [actionAlert.view valueForKeyPath:@"_messageLabel"];
        label1.textAlignment = 1;
        label2.textAlignment = 0;
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:1 handler:nil];
        [cancelAction setValue:[UIColor grayColor] forKey:@"titleTextColor"];
        UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"呼叫客服" style:0 handler:^(UIAlertAction * _Nonnull action) {
            NSMutableString *str = [[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"400-150-1200"];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:nil];
        }];
        [actionAlert addAction:sureAction];
        [actionAlert addAction:cancelAction];
        [self presentViewController:actionAlert animated:YES completion:nil];
        
    }
    
}


@end


@implementation YSBMessageHeaderView

- (void)prepareSubViewsWithItemArray {
    

}

- (void)reloadHeaderDataWithItemArray:(NSArray *)itemArray {
    
    self.itemArray = itemArray;
        
    CGFloat msgHeaderHeight = 110;

    CGFloat msgHeaderWidth = self.frame.size.width - 30;
    
    CGRect tempFrame = CGRectMake(15, 0, msgHeaderWidth, msgHeaderHeight);
    self.collectionView.frame = tempFrame;
            
    [self.collectionView reloadData];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return self.itemArray.count;
    
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat msgHeaderWidth = self.frame.size.width - 30;
    
    CGFloat dWidth = ((msgHeaderWidth) / 4) - 6;
    CGFloat dHeight = 85;
    return CGSizeMake(dWidth, dHeight);
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    // top left down right
    return UIEdgeInsetsMake(15, 5, 0, 5);
}


@end
